<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
	<c:set var="ctx" value="${pageContext.request.contextPath}" />
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>阶梯返利供应商列表</title>
	<jsp:include page="../../import.jsp" flush="true" />
</head>
<script type="text/javascript">
    var grid = null;
    var _mfrId;
    var pageInApp={}; // to 下一级子窗口 接口
    var pageInTab=null;
    var currBuOrgCd = '${currBuOrgCd}';
    $(function () {
        initTab();
        _mfrId = '${mfrId}';
        var _url = '<%=path%>/spl/rebates/initSplList.do' ;
        $("#ligergrid1").ligerGrid({
            url: _url,
			parms:{isBlackList:9,audStsCd:2},
            method : 'get',
            columns: [

				{ display: '经销商ID', name: 'id', minWidth: 120, align:'center', enabledSort:true,hide:true},
				{ display: '是否大客户', name: 'isVip', minWidth: 120, align:'center', enabledSort:true,hide:true},
                { display: '经销商名称', align:'left', width: 150,
                    render: function (rowdata, rowindex, value){
                        var h='<a href="javascript:showDetail(';
                        h+="'"+rowdata.id+"'";
                        h+=",'"+rowdata.audStsCd+"'";
                        h+=",'"+rowdata.qualTypCd+"'";
                        h+=",'"+rowdata.splAttrCd+"'";
                        h+=')">'+rowdata.splNm+'</a>';
                        return h;
                    }
                },
				{ display: '供应商星级', name: 'starLevelNm',width: 150},
                { display: '供应商属性', name: 'splAttrCd',width: 150 ,
                    render: function (rowdata, rowindex, value){
                        if(StringUtils.isNotEmpty(value) && value==CustomerConstant.CST_TYPE_NP_CD){//1自然人 2法人
                            return "自然人";
                        }else if(StringUtils.isNotEmpty(value) && value==CustomerConstant.CST_TYPE_CORP_CD){
                            return "法人";
                        }else{
                            return "未知";
                        }
                    }
                },
                { display: '所属事业部', name: 'buOrgCdNms', align:'left', width: '20%' ,isEllipsis: false,
                    render: function (rowdata, rowindex, value){
                        if(StringUtils.isEmpty(value)){
                            return "";
                        }else{
                            var h='<span class="gridTip" title="'+ value +'">'+ value +'</span>'
                            return h;
                        }
                    }
                },
				{ display: '融资额', name: 'actLsAmt',width: '20%',
					render: function (rowdata, rowindex, value){
						if(value){
							return '￥   '+value;
						}else{
							return'￥   0.00';
						}
					}
				},
            ],
            pageSize:10,
            root:'rows',
            record:'total',
            hideLoadButton : true,
            width: '100%',
            height:'100%',
            heightDiff:-2,
            checkbox:true,
            fixedCellHeight: false,
            rownumbers:true,
			frozenRownumbers: false,
//			onAfterShowData: getFlowIds,
        });
        grid = liger.get("ligergrid1");
        grid.setHeight(100);
        $("#searchBar").ligerForm();
        $('#reasonFromSet').ligerForm({
            validate : true
        });

        $("#searchBtn").click(function(event) {
            var form = new liger.get("searchBar");
            var data = form.getData();
            console.log(JSON.stringify(data));
            for (name in data){
                grid.setParm(name,data[name]);
            };
            console.info(data['loanTmStar'])
            console.info(data['loanTmEnd'])
            var month = MonthsBetw(data['loanTmStar'],data['loanTmEnd'])
			if(month <=12) {
				grid.reload();
			}else{
				$.ligerDialog.SQalert({content: "查询时间不能超过12个月！", SQ_type: "error"});
			}
        });
        $("#clearBtn").click(function(event) {
            $("#resetBtn").click();  //重置 input-text
            var form = liger.get("searchBar");
            form.setData({  //重置select等特殊表单
				"splNm":"",
				"splAttrCd":"",
                "rgnProvCd": " ",
                "rgnCityCd": " ",
                "buOrgCd": " ",
				"isBlackList":"9",
				"loanTmStar":"",
				"loanTmEnd":""
            });
        });
    });
	function MonthsBetw(date1, date2) {
		if(!date1 && !date2){
			return 0 ;
		}
		if(date2 && !date1){
			$.ligerDialog.SQalert({content: "查询起始时间为空！！", SQ_type: "error"});
		}
		if(date1 && !date2){
			$.ligerDialog.SQalert({content: "查询结束时间为空！", SQ_type: "error"});
		}
		//用-分成数组
		date1 = date1.split("-");
		date2 = date2.split("-");
		//获取年,月数
		var year1 = parseInt(date1[0]),
				month1 = parseInt(date1[1]),
				year2 = parseInt(date2[0]),
				month2 = parseInt(date2[1]),
				//通过年,月差计算月份差
				months = (year2 - year1) * 12 + (month2 - month1) + 1;
		return months;
	}
	function toadd() {
		var selectedRows = grid.getSelectedRows();
		if (selectedRows.length != 1) {
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
			return false;
		}else{
			if (loadedTabs.indexOf(selectedRows[0].id)<0) {
				loadedTabs = [];
				loadedTabs.push(selectedRows[0].id);
				splId = selectedRows[0].id ;
				splNm = selectedRows[0].splNm ;
			}
			SetIframe_height();
		}
		console.info("splid="+selectedRows[0].id+",splNm="+selectedRows[0].splNm)
		var onCancel = function (item, Dialog) {
			Dialog.hide();
		};
		$.ligerDialog.SQopen({
			width: 1000,
			//height: 800,
			autoFixHeight: true,
			title: '新增',
			url: '<%=path%>/spl/rebates/toAddPage.do?splId='+selectedRows[0].id+'&splNm='+selectedRows[0].splNm+'&isVip='+selectedRows[0].isVip,
			buttons: [
				{
					text: "关闭", onclick: onCancel, type: 'cancel'
				}
			]
		});
	}

	function getOptColumns(){
		var col =  { display: '操作', width: 300 , align:'left',	isEllipsis: false,
			render: function (rowdata, rowindex, value){
				return '';
			}
		};
		return col;
	}
    //格式化时间
    function renderDate(rowdata, index, value){
        var dateStr = "";
        if(null != value){
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }

    var loadedTabs = [];
    //初始化Tab页签
    function initTab(){
        pageInTab = $("#pageInTab").ligerTab({
            height: 'auto',
            contextmenu: false,
            minIframeHeight: GET_minIframeHeight(),
            onBeforeSelectTabItem: function(tabid) {
                var selectedRows = grid.getSelectedRows();
                if(tabid!="tabA"){

                }
            },
            onAfterSelectTabItem: function(tabid) {
				switch (tabid) {
					case "tabB":
						pageInTab.setTabItemSrc(tabid, "<%=path%>/spl/rebates/toRebateRulesListPage.do");
						break;
					case "tabC":
						pageInTab.setTabItemSrc(tabid, "<%=path%>/spl/rebates/toRebateRecord.do");
						break;
				}
            }
        });
        $.extend(true, pageInApp, {
            pageInTab: pageInTab
        });

    };
</script>

<body class="iframeBody">
<div class="Wrapper">
	<div id="pageInTab" class="pageInTab">
		<div tabid="tabA" title="阶梯返利供应商列表" lselected="true">
			<div class="searchArea">
				<form id="searchBar">
					<div class="fieldset1 clearFix">
						<div class="fieldBox">
							<div class="label">供应商名称</div>
							<div class="field">
								<input name="splNm" id="splNm" type="text" class="ui-textbox" value="">
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">供应商属性</div>
							<div class="field">
								<select name="splAttrCd" id="splAttrCd" data-value=" ">
									<option value=" " seleted>请选择</option>
									<option value="1" seleted>自然人</option>
									<option value="2" seleted>法人</option>
								</select>
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">是否黑名单</div>
							<div class="field">
								<select name="isBlackList" id="isBlackList" data-value=" ">
									<option value="9" seleted>全部</option>
									<option value="1" seleted>是</option>
									<option value="0" seleted>否</option>
								</select>
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">所属事业部</div>
							<div class="field">
								<select name="buOrgCd" id="buOrgCd" data-value=" ">
									<option value=" " seleted>请选择</option>
									<c:forEach items="${searchBuOrgList }" var="kv">
										<option value="${kv.key }">${kv.value }</option>
									</c:forEach>
								</select>
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">区域</div>
							<div class="field">
								<div class="field">
									<jsp:include page="../../system/sysRegion/region.jsp" flush="true" >
										<jsp:param name="regionShowLvl" value="2"/>
									</jsp:include>
								</div>
							</div>
						</div>
						<div class="fieldBox">
							<div class="label">放款时间</div>
							<div class="field">
								<input ligerui="width: 120" name="loanTmStar"
									   id="loanTmStar" type="text" class="ui-datepicker" value=""
									   validate="{required:true}"> - <input
									ligerui="width: 120" name="loanTmEnd" id="loanTmEnd"
									type="text" class="ui-datepicker" value=""
									validate="{required:true}">
							</div>
						</div>
						<div class="clearFix"></div>
						<div class="btnsBox formBtns notRight">
							<span id="searchBtn" class="sq-button-round">查询</span>
							<span id="clearBtn" class="sq-button-round">清空</span>
							<span id="addBtn" class="sq-button-round" onclick="toadd();">新增阶梯返利规则</span>
						</div>
					</div>
				</form>
			</div>
			<div class="sqPanel_body">
				<div id="ligergrid1" class="sq-grid"></div>
			</div>
			</div>

		<div tabid="tabB" title="阶梯返利规则记录" id="tabBId">
			<iframe frameborder="0" name="tabB" id="tabB" src=""></iframe>
		</div>
		<div tabid="tabC" title="阶梯返利记录" id="tabCId">
			<iframe frameborder="0" name="tabC" id="tabC" src=""></iframe>
		</div>
	</div>
</div>
</body>
</html>